package com.hippo.core.ui.compose.home.add

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.hippo.core.R
import com.hippo.core.core.ext.click
import com.hippo.core.ui.components.BottomSheetDialog
import com.hippo.core.ui.theme.HippoTheme

@Composable
fun PairedResultDialog(
    result:Boolean,
    onDismissRequest: () -> Unit,
    toHelp: () -> Unit,
) {

    BottomSheetDialog(
        title = stringResource(R.string.home_6),
        onDismissRequest = onDismissRequest,
        skipPartiallyExpanded = true,
    ) {

        if(result){
            PairedSuccessContent(onDismissRequest)
        }else{
            PairedFailedContent(
                toHelp = toHelp
            )
        }
    }

}



@Composable
private fun PairedSuccessContent(onBack: () -> Unit) {

    Column {

        Spacer(modifier = Modifier.weight(1F))

        Column(
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = Modifier.fillMaxWidth()
        ) {

            Image(
                painter = painterResource(R.mipmap.big_ok),
                contentDescription = null,
                modifier = Modifier.size(70.dp)
            )

            Spacer(modifier = Modifier.height(26.dp))

            Text(
                text = stringResource(R.string.home_15),
                color = Color.Black,
                style = TextStyle(
                    fontWeight = FontWeight.Bold,
                    fontSize = 25.sp
                )
            )
            Spacer(modifier = Modifier.height(26.dp))

            Text(
                text = stringResource(R.string.home_16),
                color = MaterialTheme.colorScheme.primary,
                style = TextStyle(
                    fontWeight = FontWeight.Bold,
                    fontSize = 14.sp,
                    textDecoration = TextDecoration.Underline
                ),
                modifier = Modifier.click {
                    onBack()
                }
            )

        }

        Spacer(modifier = Modifier.weight(1F))
    }
}


@Composable
private fun PairedFailedContent(toHelp: () -> Unit) {

    Column {

        Spacer(modifier = Modifier.weight(1F))

        Column(
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = Modifier.fillMaxWidth()
        ) {

            Image(
                painter = painterResource(R.mipmap.error),
                contentDescription = null,
                modifier = Modifier.size(70.dp)
            )

            Spacer(modifier = Modifier.height(26.dp))

            Text(
                text = stringResource(R.string.home_20),
                color = Color.Black,
                style = TextStyle(
                    fontWeight = FontWeight.Bold,
                    fontSize = 25.sp
                )
            )
            Spacer(modifier = Modifier.height(26.dp))

            Text(
                text = stringResource(R.string.home_21),
                color = MaterialTheme.colorScheme.primary,
                style = TextStyle(
                    fontWeight = FontWeight.Bold,
                    fontSize = 14.sp,
                    textDecoration = TextDecoration.Underline
                ),
                modifier = Modifier.click {
                    toHelp()
                }
            )

        }

        Spacer(modifier = Modifier.weight(1F))
    }
}





@Preview(showBackground = true)
@Composable
private fun PairedSuccessContentPreview() {
    HippoTheme {
        PairedSuccessContent{}
    }
}


@Preview(showBackground = true)
@Composable
private fun PairedFailedContentPreview() {
    HippoTheme {
        PairedFailedContent(
            toHelp = {

            }
        )
    }
}










